/* MOS                                                        */
/* Giordano Mion, Luca David Opromolla and Alessandro Sforza  */
/* University of Sussex, Banco de Portugal & NC State, and Bologna       */



program drop _all
clear
clear matrix
capture log close
set more off
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
cd "`path'/results"
log using "`path'/logs/MOS_wage_regression_Apr_26_2022_rev.log", replace
set mem 14g


use "`path'/computation/manager_regressions_exp", clear
merge nss ano using "`path'/computation/wage_data2" // we do this merge=3 to make sure we use the same worker-year in the wage regressions with experience in a product
keep if _merge==3
drop _merge var

keep empresa ano anoadm pemp hwage ln_firmage foreign sh_skilled sh_skilled_d vendas_euro nace2 n2emp nss new_exporter cont_exporter exit_exporter never_exporter other_exporter age educ_yrs ten manager* exp exp_* prev_size prev_prod prev_secs prev_secd prev_size_d prev_prod_d prev_sec_d tot_hours_wk v_est2 matchexp* de_* prev_firmid
compress

/*
// Attach PT exports (Exports of Portugal to the rest of the World, by nace 2-digits and year in thousands of US dollars, 1995-2005 from BACI)
sort nace2 ano
merge nace2 ano using "`path'/Export_PT_95_05_Nace2.dta"
tab _merge
tab nace2 ano if _merge==1  // exports data not available for nace2=37
tab nace2 ano if _merge==2  // some nace2-year combinations not always present in PT data
keep if _merge==3 | _merge==1
drop _merge
rename value_USD PT_exports
replace PT_exports = log(PT_exports)


// Group managers into 5 categories (1 general 2 production 3 financial 4 sales and 0 skilled+other manager+NC manager)
replace mant0 = 1 if mant5==1 | mant6==1
replace mante0 = 1 if mante5==1 | mante6==1
drop mant5 mant6 mante5 mante6
*/

// New variables
gen double age2 = age^2
gen double age_mg = age if manager==1
gen double educ_mg = educ_yrs if manager==1
gen double mge = manager*exp  /* Interaction between manager status and export experience */
gen double matmge = manager*matchexp  /* Interaction between manager status and matched export experience */
gen double matmge_ang = manager*matchexp_ang  /* Interaction between manager status and matched export experience for Angola */

/*
forvalues i=0/4 {
gen double mge`i' = mant`i'*exp  /* Interaction between manager type and export experience */
gen double matmge`i'  = mant`i'*matchexp  /* Interaction between manager type and matched export experience */
gen double matmge_ang`i'  = mant`i'*matchexp_ang  /* Interaction between manager type and matched export experience for Angola */
}
*/

// Set of firm-change dummies
sort nss ano
gen double num_emp = (nss!=nss[_n-1]) | (nss==nss[_n-1] & empresa!=empresa[_n-1])
sort nss ano
replace num_emp = num_emp+num_emp[_n-1] if nss==nss[_n-1]
tab num_emp
gen double firm1 = num_emp>=1 & num_emp!=. // (treatment dummy) firm1 = 1 if you are in your first (in the 1997-2004 period) firm or in a subsequent one; firm2 = 1 if you are in your second firm or in a subsequent one...
gen double firm2 = num_emp>=2 & num_emp!=.
gen double firm3 = num_emp>=3 & num_emp!=.
gen double firm4 = num_emp>=4 & num_emp!=.
gen double firm5 = num_emp>=5 & num_emp!=.
gen double firm6 = num_emp>=6 & num_emp!=.
gen double firm7 = num_emp>=7 & num_emp!=.
gen double firm8 = num_emp>=8 & num_emp!=.
gen double firm9 = num_emp>=9 & num_emp!=.
gen double mgfirm1 = (firm1==1 & manager==1) // (treatment dummy) firm1 = 1 if you are in your first (in the 1997-2004 period) firm or in a subsequent one and you are a manager; firm2 = 1 if you are in your second firm or in a subsequent one and you are a manager...
gen double mgfirm2 = (firm2==1 & manager==1)
gen double mgfirm3 = (firm3==1 & manager==1)
gen double mgfirm4 = (firm4==1 & manager==1)
gen double mgfirm5 = (firm5==1 & manager==1)
gen double mgfirm6 = (firm6==1 & manager==1)
gen double mgfirm7 = (firm7==1 & manager==1)
gen double mgfirm8 = (firm8==1 & manager==1)
gen double mgfirm9 = (firm9==1 & manager==1)

// Set of exp breakdown dummies
sort nss ano
gen double ten_exp = (exp==1 & exp[_n-1]==0 & nss==nss[_n-1])
replace ten_exp = 1 if (exp==1 & ano==1996) 
sort nss ano
replace ten_exp = ten_exp[_n-1] + ano - ano[_n-1] if nss==nss[_n-1] & ten_exp[_n-1]>=1 // ten_exp = 1 if this is the first year you have export experience 
tab ten_exp
gen dsten_exp13 = (ten_exp>=1 & ten_exp<=3) // (treatment dummy) dsten_exp13 = 1 if you have had export experience for three years or less 
gen dsten_exp46 = (ten_exp>=4 & ten_exp<=6)
gen dsten_exp79 = (ten_exp>=7 & ten_exp<=9)
// Interactions manager dummy with export experience year dummies
gen mg_exp13 = (dsten_exp13==1 & manager==1) 
gen mg_exp46 = (dsten_exp46==1 & manager==1)
gen mg_exp79 = (dsten_exp79==1 & manager==1)

// Set of matchexp breakdown dummies
gen dsten_mexp13 = (dsten_exp13==1 & matchexp==1)  // (treatment dummy) dsten_mexp13 = 1 if you have had matched export experience for three years or less 
gen dsten_mexp46 = (dsten_exp46==1 & matchexp==1)
gen dsten_mexp79 = (dsten_exp79==1 & matchexp==1)
// Interactions manager dummy with matched export experience year dummies
gen mg_mexp13 = (dsten_mexp13==1 & manager==1) 
gen mg_mexp46 = (dsten_mexp46==1 & manager==1)
gen mg_mexp79 = (dsten_mexp79==1 & manager==1)


// Year dummies
tab ano,gen(iano)

// Labelling
label var dsten_exp13 "1-3 Years of Export Exp."
label var dsten_exp46 "4-6 Years of Export Exp."
label var dsten_exp79 "7-9 Years of Export Exp."
label var mg_exp13 "Manager X 1-3 Yrs Export Exp."
label var mg_exp46 "Manager X 4-6 Yrs Export Exp."
label var mg_exp79 "Manager X 7-9 Yrs Export Exp."
label var firm1 "1st Firm (or later)"
label var firm2 "2nd Firm (or later)"
label var firm3 "3rd Firm (or later)"
label var firm4 "4th Firm (or later)"
label var firm5 "5th Firm (or later)"
label var firm6 "6th Firm (or later)"
label var firm7 "7th Firm (or later)"
label var firm8 "8th Firm (or later)"
label var firm9 "9th Firm (or later)"
label var mgfirm1 "1st Firm (or later) and manag."
label var mgfirm2 "2nd Firm (or later) and manag."
label var mgfirm3 "3rd Firm (or later) and manag."
label var mgfirm4 "4th Firm (or later) and manag."
label var mgfirm5 "5th Firm (or later) and manag."
label var mgfirm6 "6th Firm (or later) and manag."
label var mgfirm7 "7th Firm (or later) and manag."
label var mgfirm8 "8th Firm (or later) and manag."
label var mgfirm9 "9th Firm (or later) and manag."
label var prev_size "Size of Previous Firm"
label var prev_size_d "Size of Prev. Firm (0/1)"
label var prev_prod "App. Prod. of Previous Firm"
label var prev_prod_d "App. Prod. of Prev. Firm (0/1)"
label var prev_secs "Sector of Previous Firm Equal"
label var prev_secd "Sector of Previous Firm Diff"
label var prev_sec_d "Sector of Prev. Firm (0/1)"
label var sh_skilled_d "Sh. Skilled wks (0/1)"
label var dsten_mexp13 "1-3 Years of Matched Export Exp."
label var dsten_mexp46 "4-6 Years of Matched Export Exp."
label var dsten_mexp79 "7-9 Years of Matched Export Exp."
label var mg_mexp13 "Manager X 1-3 Yrs Matched Export Exp."
label var mg_mexp46 "Manager X 4-6 Yrs Matched Export Exp."
label var mg_mexp79 "Manager X 7-9 Yrs Matched Export Exp."



ta n2emp, gen(jobloc)
rename nace2 n2
tab n2,gen(ds_n2_)
//xi, pre(ds_) i.n2


// Other variables
gen double relsize = log(pemp)
gen double aprod = log(vendas_euro/pemp)
egen double relmeanwk_age = mean(age_mg),by(empresa ano)
egen double relsdwk_age = sd(age_mg),by(empresa ano)
egen double relmeanwk_educ = mean(educ_mg),by(empresa ano)
egen double relsdwk_educ = sd(educ_mg),by(empresa ano)
replace relsdwk_age = 0 if relsdwk_age==. & relmeanwk_age!=.
replace relsdwk_educ = 0 if relsdwk_educ==. & relmeanwk_educ!=.
gen d_age_mg = relmeanwk_age!=.
gen d_educ_mg = relmeanwk_educ!=.
recode relmeanwk_age relmeanwk_educ relsdwk_age relsdwk_educ (.=0)
gen double mge_c = mge*cont_exporter
gen double mge_n = mge*new_exporter
gen double mge_e = mge*exit_exporter
gen double mge_o = mge*other_exporter
gen double matmge_c = matmge*cont_exporter
gen double matmge_n = matmge*new_exporter
gen double matmge_e = matmge*exit_exporter
gen double matmge_o = matmge*other_exporter
sort empresa ano


// Labelling
label var exp "Export Exp. (0/1)"
label var mge "Manag. X Export Exp. (0/1)"
label var new_exporter "New Exporter (0/1)"
label var cont_exporter "Continuing Exporter (0/1)"
label var exit_exporter "Exiting Exporter (0/1)"
label var other_exporter "Other Exporter (0/1)"
label var age "Age (Years)"
label var age2 "Age Squared (Years)"
label var educ_yrs "Education (Years)"
label var ten "Tenure (Years)"
label var manager "Manager (0/1)"
label var relsize "Firm Size (log)"
label var aprod "Apparent Labor Productivity (log)"
label var ln_firmage "Firm Age (log)"
label var foreign "Foreign Ownership (0/1)"
label var sh_skilled "Share of Skilled Workers"
label var relmeanwk_age "Avg. Managers' Age"
label var relsdwk_age "Std. Dev. Managers' Age"
label var relmeanwk_educ "Avg. Managers' Education" 
label var relsdwk_educ "Std. Dev. Managers' Education"
label var matchexp "Matched Export Exp. (0/1)"
label var matmge "Manag. X Matched Export Exp. (0/1)"



su

local path = "/Users/lucadavidopromolla/Projects/MOS_rev"

local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"


/**** Regressions a la MIOP ****/
save "`path'/computation/reg_exports_tempb",replace
keep if n2>=15 & n2<=37
sum if ano==1996
sum if ano==2005
gen long nn=_n
marksample wage_sample
markout `wage_sample' empresa nss ano hwage `icontrols' `fcontrols' exp mge new_exporter cont_exporter exit_exporter other_exporter `iano' `jobloc' `ds_nace' matchexp matmge matchexp_ang matmge_ang // Keep same sample for all wage regressions
keep if `wage_sample'==1
compress
save "`path'/computation/summarystats_wageb",replace

cap drop ds_n2_11 ds_n2_12 ds_n2_13 ds_n2_14 ds_n2_40 ds_n2_41 ds_n2_45 ds_n2_50 ds_n2_51 ds_n2_52 ds_n2_55 ds_n2_60 ds_n2_61 ds_n2_62 ds_n2_63 ds_n2_64 ds_n2_65 ds_n2_66 ds_n2_67 ds_n2_70 ds_n2_71 ds_n2_72 ds_n2_73 ds_n2_74 ds_n2_75 ds_n2_80 ds_n2_85 ds_n2_90 ds_n2_91 ds_n2_92 ds_n2_93 tot_hours_wk v_est2 n2 n2emp anoadm

// Summary statistics
use "`path'/computation/summarystats_wageb",clear
// Number of workers and managers with export experience to Angola by year
cap drop __000000
table ano if exp_8==1,stat(count nss) stat(sum manager)
// Likelihood that a manager with export experience to Angola is employed by a firm exporting to Angola
reg matmge_ang i.n2 i.ano if exp_8==1 & manager==1

reg hwage i.n2 i.ano##i.matchexp_ang if exp_8==1

local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"

// Regular and Matched Export Experience
// Simple
use "`path'/computation/summarystats_wageb",clear
reg hwage `icontrols' `fcontrols' exp mge matchexp matmge new_exporter cont_exporter exit_exporter other_exporter `iano' `jobloc' `ds_nace', vce(cluster nn)
outreg2 using tables/reswage.xls,  ctitle(Baseline) `instruct' replace keep(exp mge matchexp matmge) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Baseline) `instruct' replace keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Baseline) `instruct' replace keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
estat summarize
// With firm FE
use "`path'/computation/summarystats_wageb",clear
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(empresa) tol(0.001) vce(cluster nn) 
outreg2 using tables/reswage.xls,  ctitle(Firm FE) `instruct' append keep(exp mge matchexp matmge) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Firm FE) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Firm FE) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
estat summarize
// With worker FE and firm FE
use "`path'/computation/summarystats_wageb",clear
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(nss empresa) vce(cluster nn) tol(0.001) 
outreg2 using tables/reswage.xls,  ctitle(Worker and Firm FE) `instruct' append keep(exp mge matchexp matmge) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Worker and Firm FE) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Worker and Firm FE) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
estat summarize

local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"


// Regular and Matched Export Experience - Angola
// Simple
use "`path'/computation/summarystats_wageb",clear
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
reg hwage `icontrols' `fcontrols' exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02 new_exporter cont_exporter exit_exporter other_exporter `iano' `jobloc' `ds_nace', vce(cluster nn)
outreg2 using tables/reswage.xls,  ctitle(Angola) `instruct' append keep( exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Angola) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Angola) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
display(_b[matchexp]+_b[matchexp_ang]+_b[matmge]+_b[matmge_ang])
test matchexp+matchexp_ang+matmge+matmge_ang=0   /* check if managers with matched export experience to Angola receive an additional wage premium before 2002 */
display(_b[matchexp]+_b[matchexp_ang]+_b[matchexp_ang02]+_b[matmge]+_b[matmge_ang]+_b[matmge_ang02])
test matchexp+matchexp_ang+matchexp_ang02+matmge+matmge_ang+matmge_ang02=0   /* check if managers with matched export experience to Angola receive an additional wage premium after the end of the war */
estat summarize
// With firm FE
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
use "`path'/computation/summarystats_wageb",clear
cap drop __000000
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02 new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(empresa) tol(0.001) vce(cluster nn) 
outreg2 using tables/reswage.xls,  ctitle(Angola Firm FE) `instruct' append keep( exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Angola Firm FE) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Angola Firm FE) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
display(_b[matchexp]+_b[matchexp_ang]+_b[matmge]+_b[matmge_ang])
test matchexp+matchexp_ang+matmge+matmge_ang=0   /* check if managers with matched export experience to Angola receive an additional wage premium before 2002 */
display(_b[matchexp]+_b[matchexp_ang]+_b[matchexp_ang02]+_b[matmge]+_b[matmge_ang]+_b[matmge_ang02])
test matchexp+matchexp_ang+matchexp_ang02+matmge+matmge_ang+matmge_ang02=0   /* check if managers with matched export experience to Angola receive an additional wage premium after the end of the war */
estat summarize
// With worker FE and firm FE
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
use "`path'/computation/summarystats_wageb",clear
cap drop __000000
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02 new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(nss empresa) vce(cluster nn) tol(0.001) 
outreg2 using tables/reswage.xls,  ctitle(Angola Worker and Firm FE) `instruct' append keep( exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Angola Worker and Firm FE) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Angola Worker and Firm FE) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
display(_b[matchexp]+_b[matchexp_ang]+_b[matmge]+_b[matmge_ang])
test matchexp+matchexp_ang+matmge+matmge_ang=0   /* check if managers with matched export experience to Angola receive an additional wage premium before 2002 */
display(_b[matchexp]+_b[matchexp_ang]+_b[matchexp_ang02]+_b[matmge]+_b[matmge_ang]+_b[matmge_ang02])
test matchexp+matchexp_ang+matchexp_ang02+matmge+matmge_ang+matmge_ang02=0   /* check if managers with matched export experience to Angola receive an additional wage premium after the end of the war */
display(_b[matchexp_ang]+_b[matmge_ang])
test matchexp_ang+matmge_ang=0   /* check if managers with matched export experience to Angola receive an additional wage premium after the end of the war */
display(_b[matchexp_ang]+_b[matchexp_ang02]+_b[matmge_ang]+_b[matmge_ang02])
test matchexp_ang+matchexp_ang02+matmge_ang+matmge_ang02=0   /* check if managers with matched export experience to Angola receive an additional wage premium after the end of the war */
display(_b[exp]+_b[mge]+_b[matchexp]+_b[matchexp_ang]+_b[matmge]+_b[matmge_ang])
test exp+mge+matchexp+matchexp_ang+matmge+matmge_ang=0   /* check if managers with matched export experience to Angola receive an additional wage premium before 2002 */
display(_b[exp]+_b[mge]+_b[matchexp]+_b[matchexp_ang]+_b[matmge]+_b[matmge_ang]+_b[matchexp_ang02]+_b[matmge_ang02])
test exp+mge+matchexp+matchexp_ang+matmge+matmge_ang+matchexp_ang02+matmge_ang02=0   /* check if managers with matched export experience to Angola receive an additional wage premium before 2002 */
estat summarize

local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"


// Regular and Matched Export Experience - Angola - manager type 
// Simple
use "`path'/computation/summarystats_wageb",clear
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
gen matmge_ang002 = matmge_ang0*y2002
gen matmge_ang102 = matmge_ang1*y2002
gen matmge_ang202 = matmge_ang2*y2002
gen matmge_ang302 = matmge_ang3*y2002
gen matmge_ang402 = matmge_ang4*y2002
reg hwage `icontrols' `fcontrols' exp mge matchexp matmge0 matmge1 matmge2 matmge3 matmge4 matmge_ang0 matmge_ang1 matmge_ang2 matmge_ang3 matmge_ang4 matchexp_ang02 matmge_ang002 matmge_ang102 matmge_ang202 matmge_ang302 matmge_ang402 new_exporter cont_exporter exit_exporter other_exporter `iano' `jobloc' `ds_nace', vce(cluster nn)
outreg2 using tables/reswage.xls,  ctitle(Manager Type) `instruct' append keep(mge matmge) nocons
outreg2 using tables/reswage_A.xls,  ctitle(Manager Type) `instruct' append keep(`icontrols')
outreg2 using tables/reswage_B.xls,  ctitle(Manager Type) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
// With firm FE
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
use "`path'/computation/summarystats_wageb",clear
cap drop __000000
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02 new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(empresa) tol(0.001) vce(cluster nn) 
outreg2 using tables/wage_regb.xls,  ctitle(f FE col6) `instruct' append keep(mge matmge) nocons
outreg2 using tables/wage_reg_ctrb_A.xls,  ctitle(f FE col6) `instruct' append keep(`icontrols')
outreg2 using tables/wage_reg_ctrb_B.xls,  ctitle(f FE col6) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
// With worker FE and firm FE
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod   ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = " jobloc1 jobloc2 jobloc3 jobloc4 jobloc5"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
use "`path'/computation/summarystats_wageb",clear
cap drop __000000
gen y2002 = ano>=2002
gen matchexp_ang02 =  matchexp_ang*y2002
gen matmge_ang02 = matmge_ang*y2002
reghdfe hwage `icontrols' `fcontrols' exp mge matchexp matmge matchexp_ang matmge_ang matchexp_ang02 matmge_ang02 new_exporter cont_exporter exit_exporter other_exporter `iano', absorb(nss empresa) vce(cluster nn) tol(0.001) 
outreg2 using tables/wage_regb.xls,  ctitle(wf FE col7) `instruct' append keep(mge matmge) nocons
outreg2 using tables/wage_reg_ctrb_A.xls,  ctitle(wf FE col7) `instruct' append keep(`icontrols')
outreg2 using tables/wage_reg_ctrb_B.xls,  ctitle(wf FE col7) `instruct' append keep(exp matchexp new_exporter cont_exporter exit_exporter other_exporter `fcontrols')
display(_b[exp]+_b[mge])
test exp+mge=0   /* check if managers with export experience receive a wage premium */
display(_b[matchexp]+_b[matmge])
test matchexp+matmge=0   /* check if managers with matched export experience receive an additional wage premium */
display(_b[matchexp]+_b[matmge]+_b[matmge]) /* Additional Export exp. to Angola for a manager before 2002 */


log close
